home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / Sources / FWBTxtSh.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  5.8 KB  |  192 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWBTxtSh.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1993, 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWBTXTSH_H
  13. #include "FWBTxtSh.h"
  14. #endif
  15.  
  16. //========================================================================================
  17. //    RunTime Info
  18. //========================================================================================
  19.  
  20. #if FW_LIB_EXPORT_PRAGMAS
  21. #pragma lib_export on
  22. #endif
  23.  
  24. #ifdef FW_BUILD_MAC
  25. #pragma segment fwgraphxshape
  26. #endif
  27.  
  28. FW_DEFINE_CLASS_M1(FW_CBaseTextShape, FW_CShape)
  29.  
  30. //========================================================================================
  31. //    class FW_CBaseTextShape
  32. //========================================================================================
  33.  
  34. //----------------------------------------------------------------------------------------
  35. //    FW_CBaseTextShape::FW_CBaseTextShape
  36. //----------------------------------------------------------------------------------------
  37.  
  38. FW_CBaseTextShape::FW_CBaseTextShape(const FW_CBaseTextShape& other) :
  39.     FW_CShape(other),
  40.     fString(other.fString)
  41. {
  42.     FW_END_CONSTRUCTOR
  43. }
  44.  
  45. //----------------------------------------------------------------------------------------
  46. //    FW_CBaseTextShape::FW_CBaseTextShape
  47. //----------------------------------------------------------------------------------------
  48.  
  49. FW_CBaseTextShape::FW_CBaseTextShape(const FW_CString& string,
  50.                                        const FW_PInk& ink,
  51.                                      const FW_PFont& font) :
  52.     FW_CShape(FW_kFill, ink, FW_kNormalStyle, font),
  53.     fString(string)
  54. {    
  55.     FW_END_CONSTRUCTOR
  56. }
  57.  
  58. //----------------------------------------------------------------------------------------
  59. //    FW_CBaseTextShape::FW_CBaseTextShape
  60. //----------------------------------------------------------------------------------------
  61.  
  62. FW_CBaseTextShape::FW_CBaseTextShape() :
  63.     FW_CShape(FW_kFill, FW_kOr, FW_kNormalStyle, FW_kNormalFont)
  64. {            
  65.     FW_END_CONSTRUCTOR
  66. }
  67.  
  68. //----------------------------------------------------------------------------------------
  69. //    FW_CBaseTextShape::FW_CBaseTextShape
  70. //----------------------------------------------------------------------------------------
  71.  
  72. FW_CBaseTextShape::FW_CBaseTextShape(FW_CTextReader* textReader,
  73.                                        const FW_PInk& ink,
  74.                                      const FW_PFont& font) :
  75.     FW_CShape(FW_kFill, ink, FW_kNormalStyle, font)
  76. {    
  77.     SetText(textReader);
  78.     
  79.     FW_END_CONSTRUCTOR
  80. }
  81.  
  82. //----------------------------------------------------------------------------------------
  83. //    FW_CBaseTextShape::FW_CBaseTextShape
  84. //----------------------------------------------------------------------------------------
  85.  
  86. FW_CBaseTextShape::FW_CBaseTextShape(FW_CReadableStream& archive) :
  87.     FW_CShape(archive)
  88. {
  89.     FW_CStringArchiver::Read(archive, fString);
  90.     
  91.     FW_END_CONSTRUCTOR
  92. }
  93.  
  94. //----------------------------------------------------------------------------------------
  95. //    FW_CBaseTextShape::~FW_CBaseTextShape
  96. //----------------------------------------------------------------------------------------
  97.  
  98. FW_CBaseTextShape::~FW_CBaseTextShape()
  99. {
  100.     FW_START_DESTRUCTOR
  101. }
  102.  
  103. //----------------------------------------------------------------------------------------
  104. //    FW_CBaseTextShape::operator=
  105. //----------------------------------------------------------------------------------------
  106.  
  107. FW_CBaseTextShape& FW_CBaseTextShape::operator=(const FW_CBaseTextShape& other)
  108. {
  109.     if (this != &other)
  110.     {
  111.         FW_CShape::operator=(other);
  112.         // MetroWerks bug workaround [AMB]
  113.         FW_CString& string = fString;    
  114.         string = other.fString;
  115.     }
  116.     
  117.     return *this;
  118. }
  119.  
  120. //----------------------------------------------------------------------------------------
  121. //    FW_CBaseTextShape::Flatten
  122. //----------------------------------------------------------------------------------------
  123.  
  124. void FW_CBaseTextShape::Flatten(FW_CWritableStream& archive) const
  125. {
  126.     FW_CShape::Flatten(archive);
  127.  
  128.     FW_CStringArchiver::Write(archive, fString);
  129. }
  130.  
  131. //----------------------------------------------------------------------------------------
  132. //    FW_CBaseTextShape::HitTest
  133. //----------------------------------------------------------------------------------------
  134.  
  135. FW_Boolean FW_CBaseTextShape::HitTest(FW_CGraphicContext& gc,
  136.                                       const FW_CPoint& test,
  137.                                       FW_CFixed tolerance) const
  138. {
  139.     FW_CRect bounds;
  140.     GetBounds(gc, bounds);
  141.     
  142.     bounds.Inset(-tolerance, -tolerance);
  143.  
  144.     return bounds.Contains(test);
  145. }
  146.  
  147. //----------------------------------------------------------------------------------------
  148. //    FW_CBaseTextShape::GetText
  149. //----------------------------------------------------------------------------------------
  150.  
  151. void FW_CBaseTextShape::GetText(FW_CTextWriter* textWriter) const
  152. {
  153.     // MetroWerks bug workaround [AMB]
  154.     const FW_CString& string = fString;    
  155.  
  156.     // Write string's characters to textWriter's data structure
  157.     FW_CStringReader stringReader(string);
  158.     FW_ByteCount len = stringReader.GetByteLength();
  159.     FW_Char ch;
  160.  
  161.     for (short i=0; i < len; i++)
  162.     {
  163.         ch = stringReader.GetCharacterAndAdvance();
  164.         textWriter->PutCharacterAndAdvance(ch);
  165.     }
  166. }
  167.  
  168. //----------------------------------------------------------------------------------------
  169. //    FW_CBaseTextShape::SetText
  170. //----------------------------------------------------------------------------------------
  171.  
  172. void FW_CBaseTextShape::SetText(FW_CTextReader* textReader)
  173. {
  174.     const FW_Byte* start;
  175.     FW_ByteCount length;
  176.  
  177.     // MetroWerks bug workaround [AMB]
  178.     FW_CString& string = fString;    
  179.     string.Truncate(0);                                        // empty the string
  180.     do
  181.     {
  182.         textReader->PeekRunAhead(start, length);            // get address and length of buffer
  183.         if (length > 0)
  184.         {
  185.             string.Append((const FW_Char*)start, length);    // append buffer chars to string
  186.             textReader->Advance(length);                    // advance to next buffer of chars, if any
  187.         }
  188.     }
  189.     while (length > 0);
  190. }
  191.  
  192.